<?php

/**
 * JingYao-backend
 *
 * @link     https://gitee.com/wang-zhihui-release/jingyao-backend
 * @apiDocument https://gitee.com/wang-zhihui-release/jingyao-backend/wikis/
 */

namespace App\Rules;

use App\Enums\ArticleTypeEnum;
use Illuminate\Contracts\Validation\Rule;

class ArticleCoverUrlRule implements Rule
{
    private $type;

    /**
     * Create a new rule instance.
     */
    public function __construct(int $type)
    {
        $this->type = $type;
    }

    /**
     * Determine if the validation rule passes.
     *
     * @param string $attribute
     * @param mixed $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        if ($this->type != ArticleTypeEnum::ArticleTypeRubbish) {
            if (empty($value) || strlen($value) < 10) {
                return false;
            }
        }
        return true;
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return '缺少首图信息';
    }
}
